package com.itheima.service.Impl;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @param
 * @return
 */
public class UserServiceImpl implements UserService {
    public User login(Map map) {
        //调用工具类获取session
        SqlSession session = MapperUtil.getSession();
        //获取接口代理对象
        UserMapper mapper = session.getMapper(UserMapper.class);
        //调用接口中的方法
        User user = mapper.login(map);
        MapperUtil.close(session);
        return user;
    }

    public Map findUserNameAndPasswordById(Integer id) {
        //定义返回值
        Map map = new HashMap();
        //工具类获取session
        SqlSession session = MapperUtil.getSession();
        //获取接口代理对象
        UserMapper mapper = session.getMapper(UserMapper.class);
        //调用该接口中的对应方法
        map=mapper.findUserNameAndPasswordById(id);
        MapperUtil.close(session);
        return map;
    }

    public List<Map> findMapByMap(Map parameterMap) {
        //定义返回值
        List<Map> list=new ArrayList<Map>();
        //工具类
        SqlSession session = MapperUtil.getSession();
        //获取接口代理对象
        UserMapper mapper = session.getMapper(UserMapper.class);
        //调用方法
        list =mapper.findMapByMap(parameterMap);
        MapperUtil.close(session);
        return list;
    }

    public User findByNameAndPassword(Object o1, Object o2) {
        //定义返回值
        User user = new User();
        //老一套
        SqlSession session = MapperUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
         user = mapper.findByNameAndPassword(o1, o2);
        MapperUtil.close(session);
        return user;
    }

    public List<User> findByIds(List<Integer> idList) {
        //定义返回值
        List<User> list = new ArrayList<User>();
        //老一套
        SqlSession session = MapperUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        list =mapper.findByIds(idList);
        MapperUtil.close(session);
        return list;
    }
}
